<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <title>车辆保险查询审核</title>
    <script src="jquery.js"></script>
	<script>
	$(function(){
    	// 给所有 id 以 delete_ 开头的链接绑定点击事件
    	$('a[id^="delete_"]').click(function(e){ 
        	e.preventDefault(); // 阻止默认跳转行为
        	var deleteURL = $(this).attr('href'); // 获取删除链接
        	if(confirm('确定删除该条记录吗？')){ // 弹出确认框
            	window.location.href = deleteURL; // 跳转到删除链接
        	} 
    	});
	});
	</script>
    <style>
        /* 样式表 */
        table {
            border-collapse: collapse;
            width: 100%;
        }
        th, td {
            padding: 8px;
            text-align: center;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        input[type="text"] {
            padding: 6px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            width: 200px;
        }
        button {
            background-color: #4CB2F6;
            color: white;
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0369BF;
        }
        
        .pagination {
        	position:absolute;
        	margin:20px;
        	right:0;
        	bottom:0;
            display: inline-block;
            margin-top: 16px;
        }
        .pagination a {
            color: black;
            float: left;
            padding: 8px 16px;
            text-decoration: none;
            border: 1px solid #ddd;
            margin: 0 4px;
        }
        .pagination a.active {
            background-color: #4CB2F6;
            color: white;
        }
        .pagination a:hover:not(.active) {
            background-color: #ddd;
        }
        .btn {
        	color: #1890ff;
        	padding: 8px 16px;
        	border: none;
        	border-radius: 4px;
        	cursor: pointer;
        	text-decoration: none;
    	}
    	.btn:hover{
    		text-decoration: underline;
    	}
    	#header2 {
    	width:115%;
			height: 40px;
			background: #F6F6F6;
		}
    </style>
</head>
<body>
	<%
    	String num = request.getParameter("num");
    	String place = request.getParameter("place1");
    	String type = request.getParameter("type1");
    	String sql = "SELECT * FROM car_maintenance WHERE 1=1";
    	Connection conn=null;
	%>
	<div id="header2">
		<img src="img/申请用车.png" alt="Big Boat" width="30" height="30"
			style="vertical-align: middle;"> 车辆保养 > 保养详情
	</div>
    <form method="post">
    <div style="height:50px;background-color:#DFF8FF;position:relative;display:flex;align-items:center;">
    <div style="flex:1;display:flex;align-items:center;">
        <label for="num">车牌号：</label>
        <input type="text" id="num" name="num" style="margin-right:20px;">
        <label for="type1">保养类别：</label>
        <input type="text" id="type1" name="type1" style="margin-right:20px;">
        <label for="place1">保养地点：</label>
        <input type="text" id="place1" name="place1" style="margin-right:20px;">
    </div>
    <div style="display:flex;align-items:center;">
        <button type="submit">查询</button>
    </div>
	</div>
	</form>
	
	<%
   			if (num != null && !num.isEmpty()) {
        		sql += " AND license_plate = '" + num+"'";
    		}
    		if (place != null && !place.isEmpty()) {
    			sql += " AND maintenance_location = '" + place+"'";
    		}
    		if (type != null && !type.isEmpty()) {
    			sql += " AND maintenance_type = '" + type+"'";
    		}
    		try{
				Class.forName("org.h2.Driver");//加载驱动
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				return;
			}
    		try {
        		conn = DriverManager.getConnection("jdbc:h2:d:/CompanyCar/temp/mydbtest", "sa", "");
        		Statement stmt = conn.createStatement();
        		ResultSet rs = stmt.executeQuery(sql);
	%>
    <table>
        <thead>
            <tr>
                <th>序号</th>
                <th>车牌号码</th>
                <th>保养时间</th>
                <th>保养项目</th>
                <th>保养类别</th>
                <th>保养里程</th>
                <th>保养费用</th>
                <th>保养地点</th>
                <th>经办人</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
           <% while(rs!=null && rs.next()){ %>
				<tr>
					<td><%=rs.getInt("maintenance_id") %></td>
                	<td><%=rs.getString("license_plate") %></td>
                	<td><%=rs.getDate("maintenance_date") %></td>
                	<td><%=rs.getString("maintenance_item") %></td>
                	<td><%=rs.getString("maintenance_type") %></td>
                	<td><%=rs.getFloat("maintenance_mileage") %></td>
                	<td><%=rs.getFloat("maintenance_cost") %></td>
                	<td><%=rs.getString("maintenance_location") %></td>
                	<td><%=rs.getString("handler") %></td>
					<%String queryURL="D-Details_maintenance_look.jsp?action=1&id="+rs.getInt("maintenance_id"); %>
					<%String editURL="D-Details_maintenance_edit.jsp?action=2&id="+rs.getInt("maintenance_id"); %>
					<%String deleteURL="D-JDBC-Details_maintenance_delete.jsp?action=2&id="+rs.getInt("maintenance_id"); %>
					<td>
						<a class="btn" href=<%=queryURL %>>查看</a>
						<a class="btn" href=<%=editURL %>>编辑</a>
						<a class="btn" id="delete_<%=rs.getInt("maintenance_id") %>" style="color:red" href=<%=deleteURL %> >删除</a>
					</td>
				</tr>
			<% } %>
        </tbody>
    </table>
    <div class="pagination">
        <a href="#">« 上一页</a>
        <a href="#" class="active">1</a>
        <a href="#">2</a>
        <a href="#">下一页 »</a>
    </div>
<%
        rs.close();
        stmt.close();
      //关闭表达式对象				
    	conn.close();			
    	
    } catch (SQLException e) {
    	e.printStackTrace();
    } finally{
    	//防止数据库未正常关闭
    	try{
    		if (conn!=null && (!conn.isClosed())){
    			conn.close();
    		}
    	}catch(SQLException e){
    		e.printStackTrace();
    	}
    }
%>
</body>
</html>